package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.BookDao;
import com.dao.BookDaoImpl;

import vo.Book;

/**
 * Servlet implementation class BookSelectServlet
 */
@WebServlet("/bookSelect.do")
public class BookSelectServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BookSelectServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out=response.getWriter();
		out.println("<html><body>");
		out.println("<table border=1 width='80%' align='center'>");
		out.println("<tr><td>序号</td><td>书名</td><td>价格</td><td>操作</td></tr>");
		String key=request.getParameter("key");
		System.out.println(key);
		BookDao dao=new BookDaoImpl();
		List<Book>list=dao.getAllByKey(key);
		int i=1;
		for(Book b:list) {
			out.println("<tr>");
			out.println("<td>");
			out.println(i++);
			out.println("</td>");
			
			out.println("<td>");
			out.println(b.getBookname());
			out.println("</td>");
			
			out.println("<td>");
			out.println(b.getPrice());
			out.println("</td>");
			
			out.println("<td>");
			out.println("<a href='bookDelete.do?isbn="+b.getIsbn()+"'>删除</a>");
			out.println("</td>");
			out.println("</tr>");
		}
		out.println("</table>");
		out.println("</body></html>");
		out.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
